module Schnell
  
  # this class contains items that are common between the li, map, area, span, div, and pre objects
  # it would not normally be used directly
  #
  # many of the methods available to this object are inherited from the Element class
  #  
  class NonControlElement < Element
    def initialize(page,how,what)
      @page = page
      @how = how
      @what = what
    end
  end
  
  # this class is used to deal with list item tags in the html page. It would not normally be created by users  
  class Li < NonControlElement
    ELEMENT_TYPE = "li"
    def text
      assert_exists
      return @element.asText
    end
  end
  
  # this class is used to deal with map tags in the html page. It would not normally be created by users  
  class Map < NonControlElement
    ELEMENT_TYPE = "map"
  end
  
  # this class is used to deal with area tags in the html page. It would not normally be created by users  
  class Area < NonControlElement
    ELEMENT_TYPE = "area"
    
    # used internally to locate the area
    def locate
      if @how == :url or @how == :href
        @element = @page.getByXPath("//#{self.class::ELEMENT_TYPE}[@href='#{@what}']")[0]
      elsif @how == :alt
        @element = @page.getByXPath("//#{self.class::ELEMENT_TYPE}[@alt='#{@what}']")[0]
      else
        super()
      end
    end
    private :locate
    
  end
  
  # this class is used to deal with pre tags in the html page. It would not normally be created by users  
  class Pre < NonControlElement
    ELEMENT_TYPE = "pre"
  end
  
  # this class is used to deal with Div tags in the html page.
  # It would not normally be created by users  
  class Div < NonControlElement
    ELEMENT_TYPE = "div"
  end
  
  # this class is used to deal with span tags in the html page. It would not normally be created by users  
  class Span < NonControlElement
    ELEMENT_TYPE = "span"
    
    # returns true if span contains the text
    def verify_contains(expected_value)
      assert_exists
      return true if @element.text.eql? expected_value
      return false
    end
  end
  
  # this class is used to deal with p tags in the html page. It would not normally be created by users
  class P < NonControlElement
    ELEMENT_TYPE = "p"
  end
end
